package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.Answers;
import com.qf.mapper.AnswersMapper;
import com.qf.service.AnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Administrator
 * @version V1.0
 * @Project spring_AQ
 * @Package com.qf.service.impl
 * @Description: ${TODO}
 * @Date 2021/10/3 23:25
 */

@Service
public class AnswerServiceImpl implements AnswerService {

    @Autowired
    private AnswersMapper answersMapper;

    @Override
    public void insert(Answers answer) {
        int i = answersMapper.insertSelective(answer);
        if (i != 1){
            throw new RuntimeException("回答失败");
        }
    }

    @Override
    public List<Answers> findByQuestionId(Integer id) {
        return answersMapper.selectByQuestionId(id);
    }

    @Override
    public PageInfo<Answers> findByQuestionIdAndPage(Integer pageNum, Integer pageSize, Integer qId) {
        PageHelper.startPage(pageNum, pageSize);
        List<Answers> list = answersMapper.selectByQuestionId(qId);
        PageInfo<Answers> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
